package com.fable.biz.operate.impl;

import com.fable.biz.operate.AdminUserService;
import com.fable.dal.condition.AdminUserQueryCondition;
import com.fable.dal.dto.AdminUserDTO;
import com.fable.dal.mapper.ext.AdminUserExtMapper;
import com.fable.dal.model.AdminUserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

/**
 * Created by weishuai on 18/4/7.
 */

@Service("adminUserService")
public class AdminUserServiceImpl implements AdminUserService {



    @Autowired
    AdminUserExtMapper adminUserExtMapper;



    @Override
    public int add(AdminUserDO adminUserDO) {
        adminUserDO.setGmtModified(new Date());
        adminUserDO.setGmtCreate(new Date());
        adminUserDO.setStatus(1);
        adminUserDO.setPassword("123456");
        return adminUserExtMapper.insertSelective(adminUserDO);
    }

    @Override
    public void update(AdminUserDO adminUserDO) {
        adminUserExtMapper.updateByPrimaryKeySelective(adminUserDO);
    }

    @Override
    public AdminUserDTO login(String userName, String password) {


       return  adminUserExtMapper.findAdminUserDTOByLogin(userName,password);
    }

    @Override
    public List<AdminUserDTO> findUser(AdminUserQueryCondition condition) {

        List<AdminUserDTO> list= adminUserExtMapper.findByCondition(condition);
        if(!CollectionUtils.isEmpty(list)){
            return list;
        }
        return null;
    }

    @Override
    public AdminUserDTO findDTOUserById(Integer id) {
        return adminUserExtMapper.findAdminUserDTOById(id);
    }

    @Override
    public AdminUserDO findDOUserById(Integer id) {
        return adminUserExtMapper.selectByPrimaryKey(id);
    }
}
